FROM maven:3-amazoncorretto-17-debian

LABEL maintainer="Peter Thomas"
LABEL url="https://github.com/karatelabs/karate/tree/master/karate-docker/karate-chrome"

RUN apt-get update && apt-get install -y --no-install-recommends \
    wget \
    gnupg2 \
    ca-certificates

RUN mkdir -p /etc/apt/keyrings \
  && wget -q -O - https://dl.google.com/linux/linux_signing_key.pub \
     | gpg --dearmor > /etc/apt/keyrings/google-linux-signing-key.gpg \
  && echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/google-linux-signing-key.gpg] http://dl.google.com/linux/chrome/deb/ stable main" \
     > /etc/apt/sources.list.d/google-chrome.list \
  && apt-get update \
  && apt-get install -y --no-install-recommends \
       google-chrome-stable

RUN useradd chrome --shell /bin/bash --create-home \
  && usermod -a -G sudo chrome \
  && echo 'ALL ALL = (ALL) NOPASSWD: ALL' >> /etc/sudoers \
  && echo 'chrome:karate' | chpasswd

RUN apt-get install -y --no-install-recommends \
  xvfb \
  x11vnc \
  xterm \
  fluxbox \
  wmctrl \
  supervisor \
  socat \
  ffmpeg \
  locales \
  locales-all

ENV LANG en_US.UTF-8

RUN apt-get clean \
  && rm -rf /var/cache/* /var/log/apt/* /var/lib/apt/lists/* /tmp/* \
  && mkdir ~/.vnc \
  && x11vnc -storepasswd karate ~/.vnc/passwd \
  && locale-gen ${LANG} \
  && dpkg-reconfigure --frontend noninteractive locales \
  && update-locale LANG=${LANG}

COPY supervisord.conf /etc
COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh

EXPOSE 5900 9222

ADD target/karate.jar /
ADD target/repository /usr/share/maven/ref/repository

CMD ["/bin/bash", "/entrypoint.sh"]
